<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\grid\GridView;
use backend\helpers\FileViewHelper;

/* @var $this yii\web\View */
/* @var $model backend\models\Contract */

$this->title = 'Добавление дополнительного документа';
$this->params['breadcrumbs'][] = ['label' => 'Договоры', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => 'Договор №' . $contractModel->own_number, 'url' => ['view', 'id' => $contractModel->id]];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container contract-create">

    <h1 class="main-title"><?= 'Договор №' . $contractModel->own_number . ' - ' . Html::encode($this->title) ?></h1>
    <p><?= $contractModel->subject ?></p>

    <br>

    <div class="create-form contract-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'title')->textInput() ?>


    <div class="row">
        <?= $form->field($model, 'file', ['options' => ['class' => 'col-sm-4']])->fileInput(['accept' => '.doc,.docx,.pdf,.zip']) ?>
    </div>

    <br>

    <div class="form-group">
        <?= Html::submitButton('Добавить', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<br><br>

<?= GridView::widget([
    'dataProvider' => $filesDataProvider,
    'tableOptions' => [
        'class' => 'table table-striped'
    ],
    'layout' => '{items}', 
    'columns' => [
        [
            'label' => 'Прикрепленные файлы',
            'value' => function ($model) { return FileViewHelper::simpleWithName(\backend\models\ContractFile::BUCKET_NAME, $model->filename); },
            'format' => 'raw',
        ],
        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{delete}',
            'visibleButtons' =>
            [
                'delete' => Yii::$app->user->can('deleteContract'),
            ],
            'urlCreator' => function ($action, $model, $key, $index) {
                if ($action === 'delete') {
                    return \yii\helpers\Url::to(['contract/delete-file', 'id' => $model->id]);
                }
            },
        ],
    ],
]);?>


</div>
